package cn.lili.controller.promotion;

import cn.lili.common.utils.ResultUtil;
import cn.lili.common.vo.PageVO;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.promotion.entity.dos.Advertising;
import cn.lili.modules.promotion.entity.dos.AdvertisingSpace;
import cn.lili.modules.promotion.service.AdvertisingService;
import cn.lili.modules.promotion.service.AdvertisingSpaceSerivce;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author:xiangqian
 * @date: 2024/4/17 9:20
 */
@RestController
@Api(tags = "广告位")
@RequestMapping("/promotion/advertising")
@RequiredArgsConstructor
public class AdvertisingController {

    private final AdvertisingSpaceSerivce advertisingSpaceSerivce;
    private final AdvertisingService advertisingService;

    @ApiOperation(value = "分页查询广告位列表")
    @GetMapping("/pageSpace")
    public ResultMessage<Page<AdvertisingSpace>> pageSpace(AdvertisingSpace advertisingSpace, PageVO page) {
        return ResultUtil.data(advertisingSpaceSerivce.pageSpace(advertisingSpace, page));
    }

    @ApiOperation(value = "启用/关闭广告位")
    @PostMapping("/updateStatus")
    public ResultMessage<Object> updateStatus(@RequestBody AdvertisingSpace advertisingSpace) {
        return ResultUtil.data(advertisingSpaceSerivce.updateStatus(advertisingSpace));
    }

    @ApiOperation(value = "分页查询广告列表")
    @GetMapping("/page")
    public ResultMessage<Page<Advertising>> page(Advertising advertising, PageVO page) {
        return ResultUtil.data(advertisingService.page(advertising, page));
    }

    @ApiOperation(value = "添加广告")
    @PostMapping("/save")
    public ResultMessage<Boolean> save(@RequestBody Advertising advertising) {
        return ResultUtil.data(advertisingService.save(advertising));
    }

    @ApiOperation(value = "修改广告")
    @PutMapping("/updateById")
    public ResultMessage<Boolean> updateById(@RequestBody Advertising advertising) {
        return ResultUtil.data(advertisingService.updateById(advertising));
    }

    @ApiOperation(value = "立即失效")
    @PutMapping("/updateByIdStatus")
    public ResultMessage<Boolean> updateByIdStatus(@RequestParam String id) {
        return ResultUtil.data(advertisingService.updateByIdStatus(id));
    }

    @ApiOperation(value = "删除广告")
    @DeleteMapping("/removeById")
    public ResultMessage<Boolean> removeById(@RequestParam String id) {
        return ResultUtil.data(advertisingService.removeById(id));
    }

    /************************************H5****************************/
    @ApiOperation(value = "查询最新广告")
    @GetMapping("/queryNew")
    public ResultMessage<List<Advertising>> queryNew(String openId, String spaceIndex) {
        return ResultUtil.data(advertisingService.queryNew(openId, spaceIndex));
    }
}
